/**
 * @project readnote
 * @Title UserLoginCheckInterceptor.java
 * @deprecated 普通用户登录信息验证
 * @author huxh
 * @date 2012-2-20
 **/
package com.cr.backbone.intercepter;

import com.cr.backbone.action.AppBaseAction;
import com.cr.backbone.action.LoginInfo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class UserLoginCheckInterceptor implements Interceptor {


	private boolean mustLogin=true;//是否必须登录才可访问，默认为true
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5577664330095036444L;

	public void destroy() {

	}

	public void init() {

	}

	public String intercept(ActionInvocation invocation) throws Exception {
		LoginInfo loginInfo = (LoginInfo)ActionContext.getContext().getSession().get(SessionInterceptKeys.LOGIN_USER_LOGIN_INFO_KEY);
		if( isMustLogin() ){
			if( ( loginInfo ==null || loginInfo.getUser()==null || !loginInfo.isLogin() ))
				return AppBaseAction.GLOBAL_LOGIN;
		}
		//执行所拦截action
		return invocation.invoke();
	}

	public boolean isMustLogin() {
		return mustLogin;
	}

	public void setMustLogin(boolean mustLogin) {
		this.mustLogin = mustLogin;
	}
}
